package main

import (
	"fmt"
	"net"
	"time"
)

func main() {
	listen, err := net.Listen("tcp", ":9999")
	if err != nil {
		panic(err)
	}

	clientConn, err := listen.Accept()

	fmt.Println("有一个客户端来连接了")
	tcpConn := clientConn.(*net.TCPConn)
	fmt.Printf("%+v\n", tcpConn)

	//err = tcpConn.SetKeepAlivePeriod(time.Second * 180)
	err = tcpConn.SetKeepAlive(false)
	if err != nil {
		panic(err)
	}

	i := 1
	for {
		if i > 20 {
			err := tcpConn.Close()
			if err != nil {
				fmt.Printf("%+v\n", err)
			}
		}
		i++
		fmt.Println("foo")
		time.Sleep(time.Second * 2)
	}

}
